﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using Artemis.Core;

namespace Artemis.Data.ProxyProvider
{
    internal class ProxyProviderFactory : DbProviderFactory, IServiceProvider
    {
        /// <summary>
        /// Gets the singleton instance of the EFProviderWrapper factory.
        /// </summary>
        /// <value>The singleton instance.</value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Class is immutable")]
        public static readonly ProxyProviderFactory Instance = new ProxyProviderFactory();

        public override bool CanCreateDataSourceEnumerator
        {
            get { return false; }
        }

        /// <summary>
        /// Returns a new instance of the provider's class that implements the <see cref="T:System.Data.Common.DbConnection"/> class.
        /// </summary>
        /// <returns>
        /// A new instance of <see cref="T:System.Data.Common.DbConnection"/>.
        /// </returns>
        public override System.Data.Common.DbConnection CreateConnection()
        {
            return new ProxyConnection();
        }


        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(System.Data.Common.DbProviderServices))
            {
                return ProxyProviderServices.Instance;
            }
            else
            {
                return null;
            }
        }
    }
}
